package com.yuanlp.mobileplayer.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.yuanlp.mobileplayer.service.MusicPlayerService;

/**
 * Created by 原立鹏 on 2017/7/26.
 *
 * 当网络断掉时，之前访问的网络视频资源保存到本地
 */

public class CacheUtils {

    public static void putString(Context context,String key,String values){
        //创建一个私有的文件
        SharedPreferences sharedPreferences=context.getSharedPreferences("yuan",Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(key,values).commit();
    }

    public static String  getString(Context context,String key){
        SharedPreferences sharedPreferences=context.getSharedPreferences("yuan",Context.MODE_PRIVATE);

        return sharedPreferences.getString(key,""); //默认返回空字符串
    }

    /**
     * 创建一个保存播放模式的方法
     * @param context
     * @param key
     * @param playmode
     */
    public static void putPlayMode(Context context,String key,int playmode){
        SharedPreferences sharedPreferences=context.getSharedPreferences("yuan",Context.MODE_PRIVATE);
        sharedPreferences.edit().putInt(key,playmode).commit();
    }

    public static int getPlayMode(Context context,String key){
        SharedPreferences sharedPreferences=context.getSharedPreferences("yuan",Context.MODE_PRIVATE);
        return sharedPreferences.getInt(key, MusicPlayerService.REPEAT_NORMAL);
    }
}
